/*
 *  Disc Catalog
 *  A little application to quickly catalog and find contents of your
 *  DVD archives.
 *
 *  Catalog.m
 *  The application model's root class.
 *
 *
 *  Created by Nicola Gigante on 17/12/08.
 *  Copyright (C) 2008  Nicola Gigante
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#import "Catalog.h"

@implementation Catalog

@synthesize name, discs, labelManager, labelsEnabled, lastDisc;

- (id)init
{
    self = [super init];
    if (self)
	{
		self.name = @"";
		self.discs = [NSMutableArray array];
		self.labelManager = [[LabelManager alloc] init];
		self.labelsEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"labelsEnabled"];
	}
    return self;
}

- (id) initWithCoder:(NSCoder *)decoder
{
	self = [super init];
	
	self.name = [decoder decodeObjectForKey:@"name"];
	self.discs = [decoder decodeObjectForKey:@"discs"];
	self.labelManager = [decoder decodeObjectForKey:@"labelManager"];
	self.labelsEnabled = [decoder decodeBoolForKey:@"labelsEnabled"];
	
	return self;
}

- (void) encodeWithCoder:(NSCoder *)encoder
{
	[encoder encodeObject:self.name forKey:@"name"];
	[encoder encodeObject:self.discs forKey:@"discs"];
	[encoder encodeObject:self.labelManager forKey:@"labelManager"];
	[encoder encodeBool:self.labelsEnabled forKey:@"labelsEnabled"];
}

- (unsigned) countOfDiscs
{
	return discs.count;
}

- (Disc *) objectInDiscsAtIndex:(unsigned)index
{
	return [discs objectAtIndex:index];
}

- (void) removeObjectFromDiscsAtIndex:(int)index
{
	[discs removeObjectAtIndex:index];
}

- (void) insertObject:(Disc *)object inDiscsAtIndex:(int)index
{
	object.catalog = self;
	[discs insertObject:object atIndex:index];
	self.lastDisc = object;
}
@end
